package com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.LoginAction;
import com.bean.AdminBean;
import com.exception.AdminException;
import com.exception.DBException;
import com.util.HandleInfo;


public class AdminLoginServlet extends HttpServlet
{
		
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{ 
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		

		if(null==username || null==password || "".equals(username) || "".equals(password))
		{
			try
			{
				response.sendRedirect("/lab/loginError.jsp");
				return;
			}
			catch (IOException e)
			{
				System.out.println("exception");
			}
		}
		AdminBean admin = new AdminBean();
		admin.setAdminID(username);
		admin.setPassword(password);
		
		LoginAction action = new LoginAction();
		try
		{
			action.confirmAdmin(request, response,admin);
		}
		catch (AdminException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
		}
		catch (DBException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doGet(request, response);
	}
}
